Page({
  data: {
    searchResult: []
  },
  // 输入处理函数
  onInput: function(event) {
    const query = event.detail.value;
    if (query) {
      wx.cloud.callFunction({
        name: 'searchStock',
        data: {
          query: query
        },
        success: res => {
          this.setData({
            searchResult: res.result.data
          })
        },
        fail: err => {
          console.error('[云函数] [searchStock] 调用失败', err)
        }
      })
    } else {
      this.setData({
        searchResult: []
      })
    }
  },
   // 跳转到详细页面
  detail: function(event) {
    const stockCode = event.currentTarget.dataset.item;
    wx.navigateTo({
      url: `/pages/stock/stock?stockCode=${stockCode}`
    });
  }
});
